
class counter1{ }
class counter{
    int count=0;
    counter1 a=new counter1();
    counter1 b=new counter1();
    public void increase1(){
        synchronized(b){
            count++;
        }
    }
    public void increase2(){
        synchronized(a){
            count--;
        }
    }
}
public class Main {
    static counter c=new counter();
    public static void main(String[] args) throws InterruptedException {
        Thread thread1=new Thread(()->{
            for (int i = 0; i < 50000; i++){
                c.increase1();
            }
        });
        Thread thread2=new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                c.increase2();
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(c.count);
    }
}